package com.ffs.game.scene.obj;

import com.ffs.game.scene.obj.ai.ConstAI;
import com.ffs.game.scene.obj.ai.MonsterState;
import com.ffs.game.scene.obj.ai.fsm.AbstractFSMState;
import com.ffs.game.scene.obj.ai.fsm.FSMMachine;
import com.ffs.game.scene.obj.ai.fsm.monster.MonsterActiveState;
import com.ffs.game.scene.obj.ai.fsm.monster.MonsterBornState;
import com.ffs.game.scene.obj.ai.fsm.monster.MonsterDieState;
import com.ffs.game.scene.obj.ai.fsm.monster.MonsterFightState;

import java.util.HashMap;
import java.util.Map;

/**
 * 地图对象工厂
 *
 * @author ffs80
 */
public class MapObjectFactory {

    /**
     * 创建怪物
     */
    public static Monster createMonster() {
        Monster monster = new Monster(1L, 10, 10, 50, 50);
        monster.setAiType(ConstAI.AiType.patrol);
        monster.setPatrolRadius(20);

        Map<MonsterState, AbstractFSMState<MonsterState, Monster>> stateMap = new HashMap<>();
        MonsterBornState initState = new MonsterBornState(MonsterState.born, monster);
        stateMap.put(MonsterState.born, initState);
        stateMap.put(MonsterState.fight, new MonsterFightState(MonsterState.fight, monster));
        stateMap.put(MonsterState.die, new MonsterDieState(MonsterState.die, monster));
        stateMap.put(MonsterState.active, new MonsterActiveState(MonsterState.active, monster));

        FSMMachine<AbstractFSMState<MonsterState, Monster>> fsmMachine = new FSMMachine<>(stateMap, initState);
        monster.setMonsterMachine(fsmMachine);
        return monster;
    }
}
